/** Stand-alone Slick data model for immediate use */
package models


import scala.slick.jdbc.{GetResult => GR}
import scala.slick.lifted.ProvenShape.proveShapeOf
import scala.slick.model.ForeignKeyAction

object Tables extends {
  val profile = scala.slick.driver.MySQLDriver
} with Tables

/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */
trait Tables {
  val profile: scala.slick.driver.JdbcProfile
  import profile.simple._
  import scala.slick.model.ForeignKeyAction
  import scala.slick.jdbc.{GetResult => GR}
  // NOTE: GetResult mappers for plain SQL are only generated for tables where Slick knows how to map the types of all columns.
  
  /** Entity class storing rows of table Article
   *  @param id Database column id AutoInc, PrimaryKey
   *  @param title Database column title 
   *  @param content Database column content 
   *  @param shortcontent Database column shortcontent 
   *  @param time Database column time 
   *  @param userid Database column userId  */
  case class ArticleRow(id: Int, title: String, content: String, shortcontent: Option[String], time: Option[java.sql.Timestamp], userid: Int)
  /** GetResult implicit for fetching ArticleRow objects using plain SQL queries */
  implicit def GetResultArticleRow(implicit e0: GR[Int], e1: GR[String], e2: GR[java.sql.Timestamp]): GR[ArticleRow] = GR{
    prs => import prs._
    ArticleRow.tupled((<<[Int], <<[String], <<[String], <<?[String], <<?[java.sql.Timestamp], <<[Int]))
  }
  /** Table description of table article. Objects of this class serve as prototypes for rows in queries. */
  class Article(tag: Tag) extends Table[ArticleRow](tag, "article") {
    def * = (id, title, content, shortcontent, time, userid) <> (ArticleRow.tupled, ArticleRow.unapply)
    /** Maps whole row to an option. Useful for outer joins. */
    def ? = (id.?, title.?, content.?, shortcontent, time, userid.?).shaped.<>({r=>import r._; _1.map(_=> ArticleRow.tupled((_1.get, _2.get, _3.get, _4, _5, _6.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
    
    /** Database column id AutoInc, PrimaryKey */
    val id: Column[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
    /** Database column title  */
    val title: Column[String] = column[String]("title")
    /** Database column content  */
    val content: Column[String] = column[String]("content")
    /** Database column shortcontent  */
    val shortcontent: Column[Option[String]] = column[Option[String]]("shortcontent")
    /** Database column time  */
    val time: Column[Option[java.sql.Timestamp]] = column[Option[java.sql.Timestamp]]("time")
    /** Database column userId  */
    val userid: Column[Int] = column[Int]("userId")
    
    /** Foreign key referencing User (database name user_article) */
    val userFk = foreignKey("user_article", userid, User)(r => r.id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  }
  /** Collection-like TableQuery object for table Article */
  lazy val Article = new TableQuery(tag => new Article(tag))
  
  /** Entity class storing rows of table ArticleCategory
   *  @param aId Database column a_id 
   *  @param cId Database column c_id  */
  case class ArticleCategoryRow(aId: Int, cId: Int)
  /** GetResult implicit for fetching ArticleCategoryRow objects using plain SQL queries */
  implicit def GetResultArticleCategoryRow(implicit e0: GR[Int]): GR[ArticleCategoryRow] = GR{
    prs => import prs._
    ArticleCategoryRow.tupled((<<[Int], <<[Int]))
  }
  /** Table description of table article_category. Objects of this class serve as prototypes for rows in queries. */
  class ArticleCategory(tag: Tag) extends Table[ArticleCategoryRow](tag, "article_category") {
    def * = (aId, cId) <> (ArticleCategoryRow.tupled, ArticleCategoryRow.unapply)
    /** Maps whole row to an option. Useful for outer joins. */
    def ? = (aId.?, cId.?).shaped.<>({r=>import r._; _1.map(_=> ArticleCategoryRow.tupled((_1.get, _2.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
    
    /** Database column a_id  */
    val aId: Column[Int] = column[Int]("a_id")
    /** Database column c_id  */
    val cId: Column[Int] = column[Int]("c_id")
    
    /** Primary key of ArticleCategory (database name article_category_PK) */
    val pk = primaryKey("article_category_PK", (aId, cId))
    
    /** Foreign key referencing Article (database name a_id) */
    val articleFk = foreignKey("a_id", aId, Article)(r => r.id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
    /** Foreign key referencing Category (database name c_id) */
    val categoryFk = foreignKey("c_id", cId, Category)(r => r.id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  }
  /** Collection-like TableQuery object for table ArticleCategory */
  lazy val ArticleCategory = new TableQuery(tag => new ArticleCategory(tag))
  
  /** Entity class storing rows of table Category
   *  @param id Database column id AutoInc, PrimaryKey
   *  @param name Database column name  */
  case class CategoryRow(id: Int, name: String)
  /** GetResult implicit for fetching CategoryRow objects using plain SQL queries */
  implicit def GetResultCategoryRow(implicit e0: GR[Int], e1: GR[String]): GR[CategoryRow] = GR{
    prs => import prs._
    CategoryRow.tupled((<<[Int], <<[String]))
  }
  /** Table description of table category. Objects of this class serve as prototypes for rows in queries. */
  class Category(tag: Tag) extends Table[CategoryRow](tag, "category") {
    def * = (id, name) <> (CategoryRow.tupled, CategoryRow.unapply)
    /** Maps whole row to an option. Useful for outer joins. */
    def ? = (id.?, name.?).shaped.<>({r=>import r._; _1.map(_=> CategoryRow.tupled((_1.get, _2.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
    
    /** Database column id AutoInc, PrimaryKey */
    val id: Column[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
    /** Database column name  */
    val name: Column[String] = column[String]("name")
    
    /** Index over (name) (database name cname) */
    val index1 = index("cname", name)
  }
  /** Collection-like TableQuery object for table Category */
  lazy val Category = new TableQuery(tag => new Category(tag))
  
  /** Entity class storing rows of table User
   *  @param id Database column id AutoInc, PrimaryKey
   *  @param username Database column username 
   *  @param password Database column password  */
  case class UserRow(id: Int, username: String, password: String)
  /** GetResult implicit for fetching UserRow objects using plain SQL queries */
  implicit def GetResultUserRow(implicit e0: GR[Int], e1: GR[String]): GR[UserRow] = GR{
    prs => import prs._
    UserRow.tupled((<<[Int], <<[String], <<[String]))
  }
  /** Table description of table user. Objects of this class serve as prototypes for rows in queries. */
  class User(tag: Tag) extends Table[UserRow](tag, "user") {
    def * = (id, username, password) <> (UserRow.tupled, UserRow.unapply)
    /** Maps whole row to an option. Useful for outer joins. */
    def ? = (id.?, username.?, password.?).shaped.<>({r=>import r._; _1.map(_=> UserRow.tupled((_1.get, _2.get, _3.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
    
    /** Database column id AutoInc, PrimaryKey */
    val id: Column[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
    /** Database column username  */
    val username: Column[String] = column[String]("username")
    /** Database column password  */
    val password: Column[String] = column[String]("password")
  }
  /** Collection-like TableQuery object for table User */
  lazy val User = new TableQuery(tag => new User(tag))
}